package com.zhentao.controller;

import com.zhentao.model.announcement.dto.AnnouncementDto;
import com.zhentao.model.announcement.pojo.AdAnnouncement;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.service.AdAnnouncementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/v1/admin/announcement")
@Api(tags = "AnnouncementController-后端公告管理")
public class AnnouncementController {

    @Resource
    AdAnnouncementService announcementService;

    /**
     * 后台公告管理列表（分页）
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("后台公告管理列表（分页）")
    public ResponseResult list(@RequestBody AnnouncementDto dto){
        return announcementService.getList(dto);
    }

    /**
     *
     * @return
     */
    @PostMapping("/appList")
    @ApiOperation("app公告列表展示")
    public ResponseResult appList(){
        return announcementService.appList();
    }

    /**
     * 后台公告添加
     * @param announcement
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("后台公告添加")
    public ResponseResult addAnnouncement(@RequestBody AdAnnouncement announcement){
        return announcementService.addAnnouncement(announcement);
    }

    /**
     * 后台公告修改
     * @param announcement
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("后台公告修改")
    public ResponseResult updateAnnouncement(@RequestBody AdAnnouncement announcement){
        return announcementService.updateAnnouncement(announcement);
    }

    /**
     * 后台公告状态调整
     * @param id
     * @return
     */
    @ApiOperation(("后台公告状态调整"))
    @PostMapping("/putway")
    public  ResponseResult putway(@RequestParam("id") int id ){
        return announcementService.putway(id);
    }
    @PostMapping("/delete")
    @ApiOperation(("公告硬删除"))
    public ResponseResult delete(@RequestParam("id") Integer id){
        announcementService.removeById(id);
        return ResponseResult.okResult("删除成功");
    }

}
